package com.efounder.message.struct;

import java.nio.ByteBuffer;

import com.efounder.util.CommonUtil;

public class IMStructUtil {
	public static String getMsgId(IMStruct002 struct) {
		return getMsgId(struct.getFromUserId(), struct.getToUserId(),
				struct.getTime(), struct.getMsgId(), struct.getToUserType());
	}

	public static String getMsgId(int fromUserId, int toUserId, long time,
			int msgId, byte toUserType) {
		byte[] byteArray = new byte[4 + 4 + 8 + 4 + 1];
		ByteBuffer buffer = ByteBuffer.wrap(byteArray);

		buffer.putInt(fromUserId);
		buffer.putInt(toUserId);
		buffer.putLong(time);
		buffer.putInt(msgId);
		buffer.put(toUserType);
		
		return CommonUtil.bytesToHexString(byteArray);
	}
	
	public static String getUserID(int toUserType, int uID) {
		if(toUserType == (byte)2)	toUserType = (byte)0;
		return String.valueOf(toUserType) + String.valueOf(uID);
	}
}
